
const tokens = {//存储 userName 和 token 映射关系的，通过 tokens[username].token 就可以获取token！ 以后写映射关系就可以这样做。
  admin: {
    token: 'admin-token'
  },
  editor: {
    token: 'editor-token'
  },
  admin2:{
    token: 'my-admin-token'
  },
  averageManager:{
    token: 'averageManager-token',
  },
  advanceManager:{
    token: 'advanceManager-token',
  },
  responsibleManager:{
    token: 'responsibleManager-token',
  }
}

const users = {/*角色定义吧，一个token对应于一个用户，所以用户有多少个，token就有多少个；roles就是权限，只有四种admin、averageManager、advanceManager、responsibleManager。*/
  'admin-token': {
    roles: ['admin'],//应该和权限有关吧。
    introduction: 'I am a super administrator',
    avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
    // avatar:'https://images.weserv.nl/?url=https://gimg2.baidu.com/image_search/src=http%3A%2F%2Finews.gtimg.com%2Fnewsapp_match%2F0%2F5150413297%2F0.jpg&refer=http%3A%2F%2Finews.gtimg.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1619353322&t=6ad81fddf0b27be155467d148a90f886',
    name: 'Super Admin'
  },
  'editor-token': {
    roles: ['editor'],
    introduction: 'I am an editor',
    avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
    name: 'Normal Editor'
  },
  'my-admin-token': {
    roles: ['admin2'],
    introduction: 'I am super administrator 唐家沆',
    // avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
    name: 'Super Admin TJH'
  },
  'responsibleManager-token':{
    roles:['responsibleManager'],
    introduction: '我是石油设备负责人',
    name:'张雪梅',/*https://images.weserv.nl/?url=   专门放缓存，解决403 forbidden问题*/
    avatar:'https://images.weserv.nl/?url=https://c-ssl.duitang.com/uploads/blog/201401/01/20140101181338_mLNPH.gif'
  },
  'averageManager-token':{
    roles:['averageManager'],
    introduction: '我是普通设备管理员',
    name:'张三',/*https://images.weserv.nl/?url=   专门放缓存，解决403 forbidden问题*/
    avatar:'https://images.weserv.nl/?url=https://c-ssl.duitang.com/uploads/blog/201401/01/20140101181338_mLNPH.gif'
  },
  'advanceManager-token':{
    roles:['advanceManager'],
    introduction: '我是普通设备管理员',
    name:'李四',/*https://images.weserv.nl/?url=   专门放缓存，解决403 forbidden问题*/
    avatar:'https://images.weserv.nl/?url=https://c-ssl.duitang.com/uploads/blog/201401/01/20140101181338_mLNPH.gif'
  }

}

module.exports = [
  // user login
  {
    url: '/vue-admin-template/user/login',//谁在请求它,语法是啥子？
    type: 'post',
    response: config => {
      const { username } = config.body//这里只需要验证 用户名 有没有对应的token。
      const token = tokens[username]//使用解构赋值。

      // mock error
      if (!token) {
        return {
          code: 60204,
          message: 'Account and password are incorrect.点击登录，发送的请求是/vue-admin-template/user/login，账户应该是有token对应的username'
        }
      }

      return {
        code: 20000,
        data: token,//返回过去的token要被保存起来，具体操作在store文件夹的js文件中。
        username
      }
    }
  },

  //user mylogin
  {
    url: '/my-vue-admin-template/user/login',
    type: 'post',
    response: config => {
      const { username } = config.body
      const token = tokens[username]

      // mock error
      if (!token) {
        return {
          code: 66666,
          message: 'Account and password are incorrect,账户应该是admin2,密码是?.'
        }
      }
      return {
        code: 29999,
        data: token
      }
    }
  },

  // get user info
  {
    url: '/vue-admin-template/user/info\.*',
    type: 'get',
    response: config => {
      const { token } = config.query
      const info = users[token]

      // mock error
      if (!info) {
        return {
          code: 50008,
          message: 'Login failed, unable to get user details.'
        }
      }

      return {
        code: 20000,
        data: info
      }
    }
  },

  // user logout
  {
    url: '/vue-admin-template/user/logout',
    type: 'post',
    response: _ => {
      return {
        code: 20000,
        data: 'success'
      }
    }
  }
]
